/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package messaage;

import java.util.ArrayList;

/**
 * 
 * @author Olga
 */
public class GotFriendsListMsg extends Message {

        private ArrayList<String> friendsList;
        private String strOfFriendsLst;

        public GotFriendsListMsg(String msg){
        	this.strOfFriendsLst = msg;
        	if(msg.equals("\0")) {
        		this.friendsList = new ArrayList<String>();
        	} else {
        		this.friendsList = parse(msg);
        	}
        }

	@Override
	public String toString() {
		return "FriendsListReply\n" + this.strOfFriendsLst;
	}

    private ArrayList<String> parse(String msg) {
       ArrayList<String> ans = new ArrayList<String>();
       String [] info1 = msg.split("\n");
       String [] info2 = new String [info1.length];
       for (int i = 1; i < info1.length-1; i++){
    	   info2[i] = info1[i].split(":")[1];
       }
       for (int i = 0; i < info2.length; i++){
           ans.add(info2[i]);
       }
       return ans;
    }
    
    public ArrayList<String> getListOfFriends(){
    	return this.friendsList;
    }

}
